package com.sskj.gocoinapp.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.gocoinapp.bean.BannerBean;
import com.sskj.gocoinapp.bean.GuideListBean;
import com.sskj.gocoinapp.http.HttpConfig;
import com.sskj.gocoinapp.ui.fragment.HangqingFragment;
import com.sskj.lib.bean.CoinBean;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;

import java.util.List;


public class HangqingFragmentPresenter extends BasePresenter<HangqingFragment> {

    public void getData() {
        httpService.getProduct(null)
                .execute(new JsonCallBack<HttpData<List<CoinBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<CoinBean>>> response) {
                        HttpData<List<CoinBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.updateUI(httpData.getData());
                        } else {
                            mView.finishRefresh();

                        }
                    }

                    @Override
                    public void onError(Response<HttpData<List<CoinBean>>> response) {
                        super.onError(response);
                        mView.finishRefresh();
                    }
                });
    }

    public void getBanner() {
        httpService.getBanner("0")
                .execute(new JsonCallBack<HttpData<List<BannerBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<BannerBean>>> response) {
                        HttpData<List<BannerBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.updateBanner(httpData.getData());
                        }
                    }
                });
    }

    public void getNotice() {
        httpService.getGonggaoList("1")
                .execute(new JsonCallBack<HttpData<PageBean<GuideListBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<PageBean<GuideListBean>>> response) {
                        HttpData<PageBean<GuideListBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.updateNotice(httpData.getData().getList());
                        }
                    }
                });
    }


}
